package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.limitattatchitemvo.LimitAttatchItemCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitattatchitemvo.LimitAttatchItemPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitattatchitemvo.LimitAttatchItemRespVO;
import com.cmc.cloud.cmclink.doc.vo.limitattatchitemvo.LimitAttatchItemUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.LimitAttatchItemDO;
import com.cmc.cloud.cmclink.doc.service.LimitAttatchItemService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 补充材料明细")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/attatchItem")
@Validated
public class LimitAttatchItemController {

    @Resource
    private LimitAttatchItemService limitAttatchItemService;

    @Operation(summary = "创建补充材料明细")
    @PostMapping("/create")
    public CommonResult<Void> createLimitAttatchItem(@Valid @RequestBody LimitAttatchItemCreateReqVO createReqVO) {
        limitAttatchItemService.createLimitAttatchItem(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新补充材料明细")
    @PostMapping("/update")
    public CommonResult<Void> updateLimitAttatchItem(@Valid @RequestBody LimitAttatchItemUpdateReqVO updateReqVO) {
        limitAttatchItemService.updateLimitAttatchItem(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除补充材料明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    public CommonResult<Void> deleteLimitAttatchItem(@PathVariable("id") Long id) {
        limitAttatchItemService.deleteLimitAttatchItem(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得补充材料明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("getById/{id}")
    public CommonResult<LimitAttatchItemRespVO> getLimitAttatchItem(@PathVariable("id") Long id) {
        LimitAttatchItemDO limitAttatchItem = limitAttatchItemService.getLimitAttatchItem(id);
        return CommonResult.success(BeanUtil.copyProperties(limitAttatchItem, LimitAttatchItemRespVO.class));
    }

    @Operation(summary = "获得补充材料明细")
    @Parameter(name = "mainId", description = "编号", required = true, example = "1024")
    @UseResponsePropertyAdvice
    @GetMapping("getByMainId/{mainId}")
    public CommonResult<List<LimitAttatchItemRespVO>> getByMainId(@PathVariable("mainId") Long mainId) {
        List<LimitAttatchItemDO> limitAttatchItemDos = limitAttatchItemService.getLimitAttatchItemByMainId(mainId);
        return CommonResult.success(BeanUtil.copyToList(limitAttatchItemDos, LimitAttatchItemRespVO.class));
    }

    @Operation(summary = "获得补充材料明细列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("listAll")
    public CommonResult<List<LimitAttatchItemRespVO>> getLimitAttatchItemList(@RequestParam("ids") Collection<Long> ids) {
        List<LimitAttatchItemDO> list = limitAttatchItemService.getLimitAttatchItemList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,LimitAttatchItemRespVO.class));
    }

    @Operation(summary = "获得补充材料明细分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    public CommonResult<PageResult<LimitAttatchItemRespVO>> getLimitAttatchItemPage(@Valid @RequestBody LimitAttatchItemPageReqVO pageVO) {
        PageResult<LimitAttatchItemDO> pageResult = limitAttatchItemService.getLimitAttatchItemPage(pageVO);
        List<LimitAttatchItemRespVO> results = BeanUtil.copyToList(pageResult.getList(),LimitAttatchItemRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
